
 .manifest                                   |    1 +
 kernel/common/inc/nv-drm.h                  |   36 ++++++++++++++++++++++++++++++++++++
 kernel/conftest.sh                          |   31 +++++++++++++++++++++++++++++++
 kernel/nvidia-drm/nvidia-drm-connector.c    |   14 ++++++++++++++
 kernel/nvidia-drm/nvidia-drm-connector.h    |    2 +-
 kernel/nvidia-drm/nvidia-drm-crtc.h         |    2 +-
 kernel/nvidia-drm/nvidia-drm-drv.c          |    2 +-
 kernel/nvidia-drm/nvidia-drm-encoder.h      |    2 +-
 kernel/nvidia-drm/nvidia-drm-fb.h           |    2 +-
 kernel/nvidia-drm/nvidia-drm-gem.h          |    2 +-
 kernel/nvidia-drm/nvidia-drm-helper.c       |    2 +-
 kernel/nvidia-drm/nvidia-drm-helper.h       |    2 +-
 kernel/nvidia-drm/nvidia-drm-modeset.h      |    2 +-
 kernel/nvidia-drm/nvidia-drm-os-interface.h |    2 +-
 kernel/nvidia-drm/nvidia-drm-prime-fence.h  |    2 +-
 kernel/nvidia-drm/nvidia-drm-priv.h         |    2 +-
 kernel/nvidia-drm/nvidia-drm-utils.h        |    2 +-
 17 files changed, 95 insertions(+), 13 deletions(-)

diff -Nurp a/kernel/common/inc/nv-drm.h b/kernel/common/inc/nv-drm.h
--- a/kernel/common/inc/nv-drm.h	1970-01-01 02:00:00.000000000 +0200
+++ b/kernel/common/inc/nv-drm.h	2020-02-09 23:07:31.142465482 +0200
@@ -0,0 +1,36 @@
+#ifndef _NV_DRM_H_
+#define _NV_DRM_H_
+
+#include "conftest.h"
+
+#if defined(NV_DRM_DRMP_H_PRESENT)
+#include <drm/drmP.h>
+#else
+#include <linux/agp_backend.h>
+#include <linux/file.h>
+#include <linux/init.h>
+#include <linux/jiffies.h>
+#include <linux/kernel.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+#include <asm/pgalloc.h>
+#include <linux/uaccess.h>
+
+#include <uapi/drm/drm.h>
+#include <uapi/drm/drm_mode.h>
+
+#include <drm/drm_agpsupport.h>
+#include <drm/drm_crtc.h>
+#include <drm/drm_drv.h>
+#include <drm/drm_prime.h>
+#include <drm/drm_pci.h>
+#include <drm/drm_ioctl.h>
+#include <drm/drm_sysfs.h>
+#include <drm/drm_vblank.h>
+#include <drm/drm_device.h>
+
+#include <drm/drm_gem.h>
+#endif
+
+#endif
diff -Nurp a/kernel/conftest.sh b/kernel/conftest.sh
--- a/kernel/conftest.sh	2019-10-23 18:48:14.000000000 +0300
+++ b/kernel/conftest.sh	2020-02-09 23:07:31.143465528 +0200
@@ -1080,6 +1080,9 @@ compile_test() {
             CODE="
             #if defined(NV_DRM_DRMP_H_PRESENT)
             #include <drm/drmP.h>
+            #else
+            #include <drm/drm_drv.h>
+            #include <drm/drm_prime.h>
             #endif
             #if !defined(CONFIG_DRM) && !defined(CONFIG_DRM_MODULE)
             #error DRM not enabled
@@ -1769,6 +1772,8 @@ compile_test() {
             echo "$CONFTEST_PREAMBLE
             #if defined(NV_DRM_DRMP_H_PRESENT)
             #include <drm/drmP.h>
+            #else
+            #include <drm/drm_drv.h>
             #endif
             #include <drm/drm_atomic.h>
             #if !defined(CONFIG_DRM) && !defined(CONFIG_DRM_MODULE)
@@ -1897,7 +1902,11 @@ compile_test() {
             # attached drivers") in v3.14 (2013-12-11)
             #
             CODE="
+            #if defined(NV_DRM_DRMP_H_PRESENT)
             #include <drm/drmP.h>
+            #else
+            #include <drm/drm_drv.h>
+            #endif
             int conftest_drm_driver_has_legacy_dev_list(void) {
                 return offsetof(struct drm_driver, legacy_dev_list);
             }"
@@ -1921,7 +1930,11 @@ compile_test() {
             #   2017-07-23  e6fc3b68558e4c6d8d160b5daf2511b99afa8814
             #
             CODE="
+            #if defined(NV_DRM_DRMP_H_PRESENT)
             #include <drm/drmP.h>
+            #else
+            #include <drm/drm_crtc.h>
+            #endif
 
             int conftest_drm_crtc_init_with_planes_has_name_arg(void) {
                 return
@@ -1937,7 +1950,11 @@ compile_test() {
             compile_check_conftest "$CODE" "NV_DRM_CRTC_INIT_WITH_PLANES_HAS_NAME_ARG" "" "types"
 
             CODE="
+            #if defined(NV_DRM_DRMP_H_PRESENT)
             #include <drm/drmP.h>
+            #else
+            #include <drm/drm_encoder.h>
+            #endif
 
             int conftest_drm_encoder_init_has_name_arg(void) {
                 return
@@ -1952,7 +1969,11 @@ compile_test() {
             compile_check_conftest "$CODE" "NV_DRM_ENCODER_INIT_HAS_NAME_ARG" "" "types"
 
             echo "$CONFTEST_PREAMBLE
+            #if defined(NV_DRM_DRMP_H_PRESENT)
             #include <drm/drmP.h>
+            #else
+            #include <drm/drm_plane.h>
+            #endif
 
             int conftest_drm_universal_plane_init_has_format_modifiers_arg(void) {
                 return
@@ -1979,7 +2000,11 @@ compile_test() {
                 echo "#undef NV_DRM_UNIVERSAL_PLANE_INIT_HAS_FORMAT_MODIFIERS_ARG" | append_conftest "types"
 
                 echo "$CONFTEST_PREAMBLE
+                #if defined(NV_DRM_DRMP_H_PRESENT)
                 #include <drm/drmP.h>
+                #else
+                #include <drm/drm_plane.h>
+                #endif
 
                 int conftest_drm_universal_plane_init_has_name_arg(void) {
                     return
@@ -3119,7 +3144,9 @@ compile_test() {
             # Introduce drm_framebuffer_{get,put}()) on 2017-02-28.
             #
             CODE="
+            #if defined(NV_DRM_DRMP_H_PRESENT)
             #include <drm/drmP.h>
+            #endif
             #if defined(NV_DRM_DRM_FRAMEBUFFER_H_PRESENT)
             #include <drm/drm_framebuffer.h>
             #endif
@@ -3138,7 +3165,9 @@ compile_test() {
             # Introduce drm_gem_object_{get,put}()) on 2017-02-28.
             #
             CODE="
+            #if defined(NV_DRM_DRMP_H_PRESENT)
             #include <drm/drmP.h>
+            #endif
             #if defined(NV_DRM_DRM_GEM_H_PRESENT)
             #include <drm/drm_gem.h>
             #endif
@@ -3157,7 +3186,9 @@ compile_test() {
             # introduce drm_dev_{get/put} functions) on 2017-09-26.
             #
             CODE="
+            #if defined(NV_DRM_DRMP_H_PRESENT)
             #include <drm/drmP.h>
+            #endif
             #if defined(NV_DRM_DRM_DRV_H_PRESENT)
             #include <drm/drm_drv.h>
             #endif
diff -Nurp a/kernel/nvidia-drm/nvidia-drm-connector.c b/kernel/nvidia-drm/nvidia-drm-connector.c
--- a/kernel/nvidia-drm/nvidia-drm-connector.c	2019-10-27 13:48:11.000000000 +0200
+++ b/kernel/nvidia-drm/nvidia-drm-connector.c	2020-02-09 23:07:31.143465528 +0200
@@ -20,6 +20,8 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
+#include <linux/version.h>
+
 #include "nvidia-drm-conftest.h" /* NV_DRM_ATOMIC_MODESET_AVAILABLE */
 
 #if defined(NV_DRM_ATOMIC_MODESET_AVAILABLE)
@@ -71,7 +73,11 @@ static enum drm_connector_status __nv_dr
     struct nv_drm_encoder *nv_detected_encoder = NULL;
 
     struct NvKmsKapiDynamicDisplayParams *pDetectParams = NULL;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 5, 0)
     unsigned int i;
+#else
+    struct drm_encoder *encoder = NULL;
+#endif
 
     BUG_ON(!mutex_is_locked(&dev->mode_config.mutex));
 
@@ -87,11 +93,16 @@ static enum drm_connector_status __nv_dr
         goto done;
     }
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 5, 0)
     for (i = 0;
          i < DRM_CONNECTOR_MAX_ENCODER && detected_encoder == NULL; i++) {
         struct drm_encoder *encoder;
+#else
+    drm_connector_for_each_possible_encoder(connector, encoder) {
+#endif
         struct nv_drm_encoder *nv_encoder;
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 5, 0)
         if (connector->encoder_ids[i] == 0) {
             break;
         }
@@ -102,6 +113,7 @@ static enum drm_connector_status __nv_dr
             BUG_ON(encoder != NULL);
             continue;
         }
+#endif
 
         /*
          * DVI-I connectors can drive both digital and analog
@@ -169,6 +181,8 @@ static enum drm_connector_status __nv_dr
             }
 
             detected_encoder = encoder;
+
+            break;
         }
     }
 
diff -Nurp a/kernel/nvidia-drm/nvidia-drm-connector.h b/kernel/nvidia-drm/nvidia-drm-connector.h
--- a/kernel/nvidia-drm/nvidia-drm-connector.h	2019-10-27 13:48:11.000000000 +0200
+++ b/kernel/nvidia-drm/nvidia-drm-connector.h	2020-02-09 23:07:31.143465528 +0200
@@ -27,7 +27,7 @@
 
 #if defined(NV_DRM_ATOMIC_MODESET_AVAILABLE)
 
-#include <drm/drmP.h>
+#include "nv-drm.h"
 
 #include "nvtypes.h"
 #include "nvkms-api-types.h"
diff -Nurp a/kernel/nvidia-drm/nvidia-drm-crtc.h b/kernel/nvidia-drm/nvidia-drm-crtc.h
--- a/kernel/nvidia-drm/nvidia-drm-crtc.h	2019-10-27 13:48:11.000000000 +0200
+++ b/kernel/nvidia-drm/nvidia-drm-crtc.h	2020-02-09 23:07:31.143465528 +0200
@@ -29,7 +29,7 @@
 
 #include "nvidia-drm-helper.h"
 
-#include <drm/drmP.h>
+#include "nv-drm.h"
 #include "nvtypes.h"
 #include "nvkms-kapi.h"
 
diff -Nurp a/kernel/nvidia-drm/nvidia-drm-drv.c b/kernel/nvidia-drm/nvidia-drm-drv.c
--- a/kernel/nvidia-drm/nvidia-drm-drv.c	2019-10-27 13:48:11.000000000 +0200
+++ b/kernel/nvidia-drm/nvidia-drm-drv.c	2020-02-09 23:07:31.143465528 +0200
@@ -39,7 +39,7 @@
 
 #include "nvidia-drm-ioctl.h"
 
-#include <drm/drmP.h>
+#include "nv-drm.h"
 
 /*
  * Commit fcd70cd36b9b ("drm: Split out drm_probe_helper.h")
diff -Nurp a/kernel/nvidia-drm/nvidia-drm-encoder.h b/kernel/nvidia-drm/nvidia-drm-encoder.h
--- a/kernel/nvidia-drm/nvidia-drm-encoder.h	2019-10-27 13:48:11.000000000 +0200
+++ b/kernel/nvidia-drm/nvidia-drm-encoder.h	2020-02-09 23:07:31.143465528 +0200
@@ -32,7 +32,7 @@
 #if defined(NV_DRM_DRM_ENCODER_H_PRESENT)
 #include <drm/drm_encoder.h>
 #else
-#include <drm/drmP.h>
+#include "nv-drm.h"
 #endif
 
 #include "nvkms-kapi.h"
diff -Nurp a/kernel/nvidia-drm/nvidia-drm-fb.h b/kernel/nvidia-drm/nvidia-drm-fb.h
--- a/kernel/nvidia-drm/nvidia-drm-fb.h	2019-10-27 13:48:11.000000000 +0200
+++ b/kernel/nvidia-drm/nvidia-drm-fb.h	2020-02-09 23:07:31.143465528 +0200
@@ -27,7 +27,7 @@
 
 #if defined(NV_DRM_ATOMIC_MODESET_AVAILABLE)
 
-#include <drm/drmP.h>
+#include "nv-drm.h"
 #include "nvidia-drm-gem-nvkms-memory.h"
 #include "nvkms-kapi.h"
 
diff -Nurp a/kernel/nvidia-drm/nvidia-drm-gem.h b/kernel/nvidia-drm/nvidia-drm-gem.h
--- a/kernel/nvidia-drm/nvidia-drm-gem.h	2019-10-27 13:48:11.000000000 +0200
+++ b/kernel/nvidia-drm/nvidia-drm-gem.h	2020-02-09 23:07:31.143465528 +0200
@@ -29,7 +29,7 @@
 
 #include "nvidia-drm-priv.h"
 
-#include <drm/drmP.h>
+#include "nv-drm.h"
 #include "nvkms-kapi.h"
 
 #if defined(NV_DRM_DRIVER_HAS_GEM_PRIME_RES_OBJ)
diff -Nurp a/kernel/nvidia-drm/nvidia-drm-helper.c b/kernel/nvidia-drm/nvidia-drm-helper.c
--- a/kernel/nvidia-drm/nvidia-drm-helper.c	2019-10-27 13:48:11.000000000 +0200
+++ b/kernel/nvidia-drm/nvidia-drm-helper.c	2020-02-09 23:07:31.143465528 +0200
@@ -31,7 +31,7 @@
 
 #if defined(NV_DRM_ATOMIC_MODESET_AVAILABLE)
 
-#include <drm/drmP.h>
+#include "nv-drm.h"
 #if defined(NV_DRM_DRM_ATOMIC_UAPI_H_PRESENT)
 #include <drm/drm_atomic_uapi.h>
 #endif
diff -Nurp a/kernel/nvidia-drm/nvidia-drm-helper.h b/kernel/nvidia-drm/nvidia-drm-helper.h
--- a/kernel/nvidia-drm/nvidia-drm-helper.h	2019-10-27 13:48:11.000000000 +0200
+++ b/kernel/nvidia-drm/nvidia-drm-helper.h	2020-02-09 23:07:31.143465528 +0200
@@ -27,7 +27,7 @@
 
 #if defined(NV_DRM_AVAILABLE)
 
-#include <drm/drmP.h>
+#include "nv-drm.h"
 
 /*
  * drm_dev_put() is added by commit 9a96f55034e41b4e002b767e9218d55f03bdff7d
diff -Nurp a/kernel/nvidia-drm/nvidia-drm-modeset.h b/kernel/nvidia-drm/nvidia-drm-modeset.h
--- a/kernel/nvidia-drm/nvidia-drm-modeset.h	2019-10-27 13:48:11.000000000 +0200
+++ b/kernel/nvidia-drm/nvidia-drm-modeset.h	2020-02-09 23:07:31.143465528 +0200
@@ -27,7 +27,7 @@
 
 #if defined(NV_DRM_ATOMIC_MODESET_AVAILABLE)
 
-#include <drm/drmP.h>
+#include "nv-drm.h"
 
 struct drm_atomic_state *nv_drm_atomic_state_alloc(struct drm_device *dev);
 void nv_drm_atomic_state_clear(struct drm_atomic_state *state);
diff -Nurp a/kernel/nvidia-drm/nvidia-drm-os-interface.h b/kernel/nvidia-drm/nvidia-drm-os-interface.h
--- a/kernel/nvidia-drm/nvidia-drm-os-interface.h	2019-10-27 13:48:11.000000000 +0200
+++ b/kernel/nvidia-drm/nvidia-drm-os-interface.h	2020-02-09 23:07:31.143465528 +0200
@@ -29,7 +29,7 @@
 
 #if defined(NV_DRM_AVAILABLE)
 
-#include <drm/drmP.h>
+#include "nv-drm.h"
 
 /* Set to true when the atomic modeset feature is enabled. */
 extern bool nv_drm_modeset_module_param;
diff -Nurp a/kernel/nvidia-drm/nvidia-drm-prime-fence.h b/kernel/nvidia-drm/nvidia-drm-prime-fence.h
--- a/kernel/nvidia-drm/nvidia-drm-prime-fence.h	2019-10-27 13:48:11.000000000 +0200
+++ b/kernel/nvidia-drm/nvidia-drm-prime-fence.h	2020-02-09 23:07:31.143465528 +0200
@@ -27,7 +27,7 @@
 
 #if defined(NV_DRM_AVAILABLE)
 
-#include <drm/drmP.h>
+#include "nv-drm.h"
 
 #if defined(NV_DRM_DRIVER_HAS_GEM_PRIME_RES_OBJ)
 
diff -Nurp a/kernel/nvidia-drm/nvidia-drm-priv.h b/kernel/nvidia-drm/nvidia-drm-priv.h
--- a/kernel/nvidia-drm/nvidia-drm-priv.h	2019-10-27 13:48:11.000000000 +0200
+++ b/kernel/nvidia-drm/nvidia-drm-priv.h	2020-02-09 23:07:31.143465528 +0200
@@ -27,7 +27,7 @@
 
 #if defined(NV_DRM_AVAILABLE)
 
-#include <drm/drmP.h>
+#include "nv-drm.h"
 
 #if defined(NV_DRM_DRM_GEM_H_PRESENT)
 #include <drm/drm_gem.h>
diff -Nurp a/kernel/nvidia-drm/nvidia-drm-utils.h b/kernel/nvidia-drm/nvidia-drm-utils.h
--- a/kernel/nvidia-drm/nvidia-drm-utils.h	2019-10-27 13:48:11.000000000 +0200
+++ b/kernel/nvidia-drm/nvidia-drm-utils.h	2020-02-09 23:07:31.143465528 +0200
@@ -27,7 +27,7 @@
 
 #if defined(NV_DRM_ATOMIC_MODESET_AVAILABLE)
 
-#include <drm/drmP.h>
+#include "nv-drm.h"
 #include "nvkms-kapi.h"
 
 struct NvKmsKapiConnectorInfo*
